import math


def cal(x1, y1, x2, y2, r1, r2):
    # 在一元二次方程中
    # a * x ^ 2 + b * x + c = 0
    # x的两个根
    # x_1, x_2
    # y的两个根
    # y_1, y_2

    global x_1
    x_1 = 0
    global x_2
    x_2 = 0
    global y_1
    y_1 = 0
    global y_2
    y_2 = 0

    # 判别式的值
    delta = -1

    if y1 != y2:
        A = (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2 + r2 ** 2 - r1 ** 2) / (2 * (y1 - y2))
        B = (x1 - x2) / (y1 - y2)
        a = 1 + B ** 2
        b = -2 * (x1 + (A - y1) * B)
        c = x1 ** 2 + (A - y1) ** 2 - r1 ** 2
        # 下面使用判定式判断是否有解
        delta = b ** 2 - 4 * a * c
        if delta > 0:
            x_1 = (-b + math.sqrt(delta)) / (2 * a)
            x_2 = (-b - math.sqrt(delta)) / (2 * a)
            y_1 = A - B * x_1
            y_2 = A - B * x_2
        elif delta == 0:
            x_1 = x_2 = -b / (2 * a)
            y_1 = y_2 = A - B * x_1
        else:
            print("两个圆不相交")
            return None
    elif x1 != x2:
        # 当y1=y2时，x的两个解相等
        x_1 = x_2 = (x1 ** 2 - x2 ** 2 + r2 ** 2 - r1 ** 2) / (2 * (x1 - x2))
        a = 1
        b = -2 * y1
        c = y1 ** 2 - r1 ** 2 + (x_1 - x1) ** 2
        delta = b ** 2 - 4 * a * c
        if delta > 0:
            y_1 = (-b + math.sqrt(delta)) / (2 * a)
            y_2 = (-b - math.sqrt(delta)) / (2 * a)
        elif delta == 0:
            y_1 = y_2 = -b / (2 * a)
        else:
            print("两个圆不相交")
            return None
    else:
        print("无解")
        return None
    return x_1, y_1, x_2, y_2


#print(cal(0, 0, 100, 100, 100, 200))
